package com.anosine.gpsl.android.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.anosine.gpsl.android.R;
import com.anosine.gpsl.android.entity.Login;
import com.anosine.gpsl.android.entity.ModifyPwdInfo;
import com.anosine.gpsl.android.presenter.AddFamilyNumberPresenter;
import com.anosine.gpsl.android.presenter.BasePresenterActivity;
import com.anosine.gpsl.android.ui.AddFamilyNumberView;
import com.anosine.gpsl.android.util.ToastHelper;
import com.anosine.gpsl.android.util.UserInfoProxy;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

/**
 * @Title: AddFamilyNumberActivity
 * @Package com.anosine.gpsl.android.ui.activity
 * @Description:
 * @author: sunny
 * @date: 2015-12-1
 * @version V1.0
 */
public class AddFamilyNumberActivity extends BasePresenterActivity implements
		AddFamilyNumberView {
	@ViewInject(R.id.content_tv_title)
	TextView title;
	@ViewInject(R.id.addNumber)
	EditText Number;
	Login userInfo;

	/**
	 * @Title: BackOnClick(View v)
	 * @Description: 返回按钮的点击事件，点击关闭当前activity
	 * @param: View v
	 * @return: 无
	 * @throws
	 */
	@OnClick(R.id.button_left)
	private void BackOnClick(View v) {
		finish();
	}

	/**
	 * @Title: AddNumberOnClick(View v)
	 * @Description: 添加按钮的点击事件
	 * @param: View v
	 * @return: 无
	 * @throws
	 */
	@OnClick(R.id.Add)
	private void AddNumberOnClick(View v) {
		// 启动MVP
		initActivityOfAddFamilyNumber();
	}

	/**
	 * @Title: onCreate(Bundle savedInstanceState)
	 * @Description: 初始化
	 * @param: savedInstanceState
	 * @return: 无
	 * @throws
	 */
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_addfamilynumber_layout);
		ViewUtils.inject(this);
		title.setText("添加亲情号");
	}

	/**
	 * @Title: initActivityOfAddFamilyNumber()
	 * @Description: 调用添加亲情号接口
	 * @param: 无
	 * @return: 无
	 * @throws
	 */
	private void initActivityOfAddFamilyNumber() {
		// 将合成的URL传给服务器
		userInfo = UserInfoProxy.getInstance().getLoginInfo();
		AddFamilyNumberPresenter presenter = new AddFamilyNumberPresenter(this);
		presenter.loadAddFamilyNumber(userInfo.userMd5, Number.getText()
				.toString());
	}

	/**
	 * @Title: setAddFamilyNumber(ModifyPwdInfo t)
	 * @Description: 解析添加亲情号后的返回信息
	 * @param: t
	 * @return: 无
	 * @throws
	 */
	@Override
	public void setAddFamilyNumber(ModifyPwdInfo t) {
		if ("msg_creat_true".equals(t.message)) {
			ToastHelper.toast("亲情号创建成功!");
			FamilyNumberActivity m = new FamilyNumberActivity();
			m.initActivityOfgetFamilyNumber();
			finish();
		} else if ("msg_creat_flase".equals(t.message)) {
			ToastHelper.toast("创建用户失败!");
		}
		if ("msg_username_false".equals(t.message)) {
			ToastHelper.toast("此号码已经被设置，请重新设置!");
		}
	}

}
